package cn.zzq.aix.nativeinterface.javareflector;

import java.util.Set;

import com.google.appinventor.components.runtime.collect.Sets;

import android.util.Log;

public class Logger {
	public static final String LOG_TAG = "JavaReflectorBase";
	public static boolean debugMode = false;

	public interface LogHandler {
		public void log(String methodName, Object... objects);
	}

	public static Set<LogHandler> logHandlers = Sets.newHashSet();

	public static void registerLogHandler(LogHandler logHandler) {
		logHandlers.add(logHandler);
	}

	public static void UnregisterLogHandler(LogHandler logHandler) {
		logHandlers.remove(logHandler);
	}

	public static void log(String methodName, Object... objects) {
		for (LogHandler logHandler : logHandlers) {
			logHandler.log(methodName, objects);
		}
		if (debugMode) {
			if (Util.isAndroidEnvironment()) {
				Log.d(LOG_TAG, "\"" + methodName + "\":" + methodName + ArrayUtil.array2json(objects));
			} else {
				String str = "\"" + methodName + "\":" + ArrayUtil.array2json(objects);
				System.out.println(str);
			}
		}
	}

}
